#ifndef TYPES_H
#define TYPES_H

#define PACKED __attribute__ ((__packed__))


#define TAVM_VERSION 1

#define MAX_LIST_SIZE 256

typedef int int32;
typedef unsigned int  uint32;
typedef unsigned int  t4B;
typedef unsigned short t2B;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned char t1B;

typedef t2B dtype_t;
typedef t4B pos_t;
typedef t1B port_t;
typedef t1B tid_t;
typedef t4B addr_t;
typedef t1B aid_t;
typedef t2B opcode_t;
typedef t2B fun_t;
typedef t1B pdir_t;
typedef t1B pstate_t;
typedef t1B list_size_t;

//#ifndef __unix__
typedef uint32 time_stamp_t;
//#endif

#define CM_EQUAL    0x00000001
#define CM_GREATER  0x00000002
#define CM_LOWER    0x00000004
#define CM_READY    0x00000008


struct tavm_table
{
    addr_t start;
    addr_t size;
} PACKED;

enum _TID
{
    TID_CTRL = 0,

    TID_STATIC,
    TID_AGENTS_S,
    TID_CODE,
    TID_PORTS_S,
    TID_DATA_MAP,
    TID_DATA_S,

    TID_VAR,
    TID_AGENTS_V,
    TID_PORTS_V,
    TID_DATA_V


};

enum _DT
{
    DT_BYTE = 0,
    DT_INT16,
    DT_UINT16,
    DT_INT32,
    DT_UINT32,
    DT_LIST,
    DT_SIGNAL
};

enum _AS
{
    AS_INIT = 0,
    AS_WAITING,
    AS_FINISHED,
    AS_RUNNING,
    AS_READY,
    AS_TAKEN
};

enum _JC
{
    JC_NC = 0,
    JC_EQUAL,
    JC_NEQUAL,
    JC_GREATER,
    JC_LOWER,
    JC_READY
};

enum _PS
{
    PS_READY = 0,
    PS_WWD,
    PS_WFD
};

enum _PDIR
{
    PDIR_IN = 0,
    PDIR_OUT,
    PDIR_INOUT
};

struct Agent_Static
{
    char name[20];
    pos_t start;
}PACKED;

struct Agent_Var
{
    pos_t pc;
    t1B state;
    uint32 condition;
    int critical;
    aid_t procAgent;
    time_stamp_t countdown;
    time_stamp_t last;
}PACKED;

struct DataEntry
{
    dtype_t type;
    tid_t tid;
    pos_t pos;
}PACKED;

struct Port_Static
{
    aid_t aid;
    pdir_t dir;
    port_t cCount;
    pos_t portsPos;
}PACKED;


struct Port_Var
{
    pstate_t state;
    pos_t dataPos;
}PACKED;

struct Port_External
{
    dtype_t type;
    pstate_t state;
}PACKED;



typedef void(*_OPCFun)(struct Agent_Var*);


#endif
